package com.hqs.listener.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.KeyEvent;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.hqs.common.utils.ActivityUtil;
import com.hqs.common.utils.ScreenUtils;
import com.hqs.common.utils.StatusBarUtil;
import com.hqs.listener.R;

public class StartActivity extends AppCompatActivity {

    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.transparencyBar(this);
        ScreenUtils.setScreenOrientationPortrait(this);

        ActivityUtil.hideActionBar(this);

        // 设置界面元素
        RelativeLayout relativeLayout = contentView();
        this.setContentView(relativeLayout);
    }

    @Override
    protected void onStart() {
        super.onStart();

        // 延时一段时间后跳转到应用主界面
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(StartActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 400);

    }

    public RelativeLayout contentView() {
        final RelativeLayout relativeLayout = new RelativeLayout(this);
        relativeLayout.setBackgroundResource(R.color.startBgColor);
        relativeLayout.setGravity(Gravity.CENTER);

        relativeLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                ImageView logo = new ImageView(StartActivity.this);
                logo.setImageResource(R.mipmap.logo);
                int wh = (int) (ScreenUtils.screenW(StartActivity.this) * 0.99);
                logo.setLayoutParams(new RelativeLayout.LayoutParams(wh, wh));
                logo.setScaleType(ImageView.ScaleType.FIT_XY);
                relativeLayout.addView(logo);
            }
        }, 200);

        return relativeLayout;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return true;
    }
}